// pagesDoctor/prescriptionPreview/index.js
import {
  ApisubmitDoctorAdvice,
} from '../../api/docIndex'
const app = getApp()
Page({


  /**
   * 页面的初始数据
   */
  data: {},


  /**
   * 生命周期函数--监听页面加载
   */


  onLoad(options) {
    /*   console.log(options) */
    let data = JSON.parse(options.subData)
    console.log(data.dosesNumber)
    this.setData({
      adviceArr: data,
    })
  },



  //提交当前数据
  submitBtn() {
    let that = this
    wx.showModal({
      title: "是否确认开处方？",
      success(res) {
        if (res.confirm) {
          /*    that.data.subData.medical[that.data.subData.medical.length - 1].dosage = that.data.dosage */
          that.data.adviceArr.medical = JSON.stringify(that.data.adviceArr.medical)
          ApisubmitDoctorAdvice(that.data.adviceArr).then(res => {
            if (res.code == '200') {
              /*  that.sendPrescriptions(JSON.stringify({
                 ...query,
                 preMessageId: res.data.id
               }), msgData.consultation_order_id, msgData.doctor_id) */
              wx.removeStorage({
                key: 'preDataChines',
                success: (res) => {
                  setTimeout(() => {
                    wx.navigateBack({
                      delta: 3
                    })
                  }, 1000);
                },
              })

            }
          })
        }
      }
    })
  },

  sendPrescriptions(val, consultation_order_id, doctor_id) {
    console.log('valvalval', val)
    const parmas = {
      consultation_order_id: consultation_order_id,
      action: "message",
      receiver: doctor_id,
      content: val,
      type: "prescription",
      sender: wx.getStorageSync('userInfo').id,
      sender_type: "doctor",
      id: Date.now()
    }
    app.ws.send(parmas)

  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})